import random
import requests
import time
from get_anti_content import get_anti_content, get_proxy_no, get_access_token

cookies = {
    '_bee': 'j4sFD92EXhkNW1g6CBXTtVFhzZfFD0yO',
    '_f77': 'eff1e851-acec-4086-a75c-8103cb0a5907',
    '_a42': 'be292171-864e-45ac-a08b-68971f365e12',
    'rckk': 'j4sFD92EXhkNW1g6CBXTtVFhzZfFD0yO',
    'ru1k': 'eff1e851-acec-4086-a75c-8103cb0a5907',
    'ru2k': 'be292171-864e-45ac-a08b-68971f365e12',
    'JSESSIONID': '1C3FEBF2259448375A78D6BC542811C3',
    'api_uid': 'CiYY3mY83oxmEABoQxZcAg==',
}

headers = {
    'accept': 'application/json, text/plain, */*',
    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7',
    'accesstoken': 'CTUN4APDU74Y3NDI2YTR2JIIA25YIDHPAIGKJ2PVHUP4UC6YHEIQ1200774',
    'anti-content': '0asAfx5EMwCEQP7JXANCSsVPOXfh_WXhEA5BfbqFjRlES5BJX0bBXw1eWakxW4EhE8xGeHVg7XrbYTTjmBbt1HV9e4LBmja0yZi5zkb9LpkExVh9LUvPtIpNTkguY9z_Gda7Cew5ExQTvwiTxqTHfOfPMczxT6jvV8XEr5G7QUdwnEAZ9A_5EYSbb6_HExQbVMhXomaWKFSlXmNMDg3CAgbNxYBqTUXV3U7XZ3lE059ofwxmaG0WI9SDZTaSB_o8f7nK95qyhngVUlsciOcs0ft_CItHWpjOycti9KqNjftNbsPGYU-vYRitGRyKf5VRGSnjTbn-2XbQl_X0PqX09YXpEaXG9yX5manu982D9O5XJX0E8XYOb4B9abwiTzcSxPHXqOGB_oqWWlHXSnqgovniTadnXt2ehA7sqobV_CEBhCez4O92mxXH2dIYgayswaG4Sf_ajlpo0nGig8nYWzXYwTyo0j4W6jys6PqOjXvJslpO-XjseaYZofYd-dn5dJy0g2TPpCxGDgKgLIFT_lZP0mxxq4ZXXGdhwGPYORx5Xinq_UQG5ptXIZKqq3PGT8I4SuQGAC9IEagIIHPXJdh502aGEYP5aRQGyYytNHQmdrQq6e8_oWtHmIQ03hCCZuNNonpZhnYXKcGsUCbeyeBBhuBzV5SvR_Ll5HF2jegfphM8iIhjn5BlQ7g1fiDGY0mE6Y9x9T9d57TW2KvjON-',
    'cache-control': 'no-cache',
    'content-type': 'application/json;charset=UTF-8',
    'origin': 'https://ktt.pinduoduo.com',
    'priority': 'u=1, i',
    'referer': 'https://ktt.pinduoduo.com/',
    'sec-ch-ua': '"Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
    # 'cookie': '_bee=j4sFD92EXhkNW1g6CBXTtVFhzZfFD0yO; _f77=eff1e851-acec-4086-a75c-8103cb0a5907; _a42=be292171-864e-45ac-a08b-68971f365e12; rckk=j4sFD92EXhkNW1g6CBXTtVFhzZfFD0yO; ru1k=eff1e851-acec-4086-a75c-8103cb0a5907; ru2k=be292171-864e-45ac-a08b-68971f365e12; JSESSIONID=1C3FEBF2259448375A78D6BC542811C3; api_uid=CiYY3mY83oxmEABoQxZcAg==',
}

params = {
    'proxy_no': get_proxy_no(),
}

headers['accesstoken'] = get_access_token()

def image_signature():
    headers['anti-content'] = get_anti_content()
    json_data = {
        'bucket_tag': 'monica',
        'sign': ''.join(random.choice('0123456789ABCDEF') for _ in range(32)),
        'signVersion': 'sv1',
        'timestamp': int(time.time() * 1000),
    }
    
    print('POST', 'https://api.pinduoduo.com/image/signature', json_data)
    response = requests.post(
        'https://api.pinduoduo.com/image/signature',
        params=params,
        cookies=cookies,
        headers=headers,
        json=json_data,
    )
    return response.json()

# for i in range(10):
#     print(f"{i}: {image_signature()}")
#     time.sleep(1.5)
    